package net.cooltain.warhammer.running.window;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import javax.swing.border.LineBorder;

import net.cooltain.warhammer.framework.constant.ConstantCardRace;
import net.cooltain.warhammer.framework.constant.ConstantCardTeamLimit;
import net.cooltain.warhammer.framework.constant.ConstantCardType;
import net.cooltain.warhammer.framework.constant.ConstantPicture;
import net.cooltain.warhammer.framework.constant.ConstantPlayZone;
import net.cooltain.warhammer.running.entity.MotionCard;
import net.cooltain.warhammer.running.entity.MotionPlayerZone;
import net.cooltain.warhammer.running.start.GameBoardDouble;
import net.cooltain.warhammer.running.window.button.Phases0BeginingBtn;
import net.cooltain.warhammer.running.window.button.Phases1KingdomBtn;
import net.cooltain.warhammer.running.window.button.Phases2QuestBtn;
import net.cooltain.warhammer.running.window.button.Phases3CapitalBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle1ChooseZoneBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle2ChooseAttackBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle3ChooseDefendBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle4AttackDmgBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle5DefendDmgBtn;
import net.cooltain.warhammer.running.window.button.Phases4Battle6CalcDmgBtn;
import net.cooltain.warhammer.running.window.button.Phases4BattleBtn;
import net.cooltain.warhammer.running.window.button.Phases5EndTurnBtn;
import net.cooltain.warhammer.running.window.command.AttackToBattleZoneBtn;
import net.cooltain.warhammer.running.window.command.AttackToKingdomZoneBtn;
import net.cooltain.warhammer.running.window.command.AttackToQuestZoneBtn;
import net.cooltain.warhammer.running.window.command.FinishChooseAttackDamageBtn;
import net.cooltain.warhammer.running.window.command.FinishChooseAttackUnitBtn;
import net.cooltain.warhammer.running.window.command.FinishChooseDefendDamageBtn;
import net.cooltain.warhammer.running.window.command.FinishChooseDefendUnitBtn;
import net.cooltain.warhammer.running.window.command.FirstTurnBtn;
import net.cooltain.warhammer.running.window.command.NextPhasesBtn;
import net.cooltain.warhammer.running.window.command.SkipBattlePhasesBtn;
import net.cooltain.warhammer.running.window.panel.CapitalLabel;
import net.cooltain.warhammer.running.window.panel.CardLabel;
import net.cooltain.warhammer.running.window.panel.DeskCardLabel;
import net.cooltain.warhammer.running.window.panel.DisCardLabel;
import net.cooltain.warhammer.running.window.panel.HandZoneLabel;
import net.cooltain.warhammer.running.window.panel.PlayZoneCardLabel;
import net.cooltain.warhammer.running.window.panel.PreviewCardLabel;

public class MainFrame extends JFrame implements MouseListener {
	
	private static final long serialVersionUID = 4899384763327831975L;
	
	private static final int WIN_WIDTH = 1100;
	private static final int WIN_HEIGHT= 740;
	
	private static final String WIN_TITLE = "战锤-入侵";
	private static final int WIN_TITLE_H= 30;

	
	public static final int PREVIEW_AREA_X = 2;
	public static final int PREVIEW_AREA_Y = 2;
	public static final int PREVIEW_AREA_W = 240;
	public static final int PREVIEW_AREA_H = WIN_HEIGHT;
	
	private static final int PREVIEW_CARD_X = PREVIEW_AREA_X;
	private static final int PREVIEW_CARD_Y = PREVIEW_AREA_Y;
	private static final int PREVIEW_CARD_W = 199;
	private static final int PREVIEW_CARD_H = 280;
	
	private static final int PREVIEW_DESC_W = PREVIEW_CARD_W;
	private static final int PREVIEW_DESC_H = WIN_HEIGHT-PREVIEW_CARD_Y-PREVIEW_CARD_H;
	
	private static final int BOARD_X = PREVIEW_AREA_W+10;
	private static final int BOARD_Y= 0;
	
	private static final int BOARD_WIDTH = WIN_WIDTH -PREVIEW_CARD_W-100;
	private static final int BOARD_HEIGHT= WIN_HEIGHT-BOARD_Y-20;
	private static final int BOARD_CENTER_X = BOARD_WIDTH/2;
	private static final int BOARD_CENTER_Y = BOARD_HEIGHT/2;
	
	private static final int USER_LABEL_WIDTH  =100;
	private static final int USER_LABEL_HEIGHT =115;
	private static final int USER_LABEL_X      =BOARD_X;
	private static final int USER_LABEL_Y      =BOARD_Y+BOARD_HEIGHT-USER_LABEL_HEIGHT-15;
	private static final int USER_LABEL_X_OPE  =BOARD_X;
	private static final int USER_LABEL_Y_OPE  =BOARD_Y;
	
	public static final int CARD_W = 50;
	public static final int CARD_H = 70;
	
	private static final int PHASES_DADDING = 4;
	private static final int PHASES_ZONE_LITTLE_W = 75;
	private static final int PHASES_ZONE_LITTLE_H = 23;
	private static final int PHASES_ZONE_W = PHASES_ZONE_LITTLE_W+PHASES_DADDING*2;
	private static final int PHASES_ZONE_H = (PHASES_ZONE_LITTLE_H+PHASES_DADDING)*13+PHASES_DADDING;
	private static final int PHASES_ZONE_X = BOARD_X+BOARD_WIDTH-PHASES_ZONE_W-10;
	private static final int PHASES_ZONE_Y = BOARD_Y+150;
	
	private static final int USER_COMMAND_W = 90;
	private static final int USER_COMMAND_H = 150;
	private static final int USER_COMMAND_X = BOARD_WIDTH-USER_COMMAND_W-10;
	private static final int USER_COMMAND_Y = BOARD_HEIGHT-USER_COMMAND_H-30;
	
	private static final int HAND_ZONE_W     = 550;
	private static final int HAND_ZONE_H     = CARD_H+10;
	private static final int HAND_ZONE_X     = (BOARD_WIDTH-HAND_ZONE_W)/2;
	private static final int HAND_ZONE_Y     = BOARD_HEIGHT-HAND_ZONE_H ;
	private static final int HAND_ZONE_X_OPE = HAND_ZONE_X;
	private static final int HAND_ZONE_Y_OPE = 0;	
	
	private static final int ZONE_MIDDLE_H = CARD_H*2+15;	
	
	private static final int CAPITAL_ZONE_W     = 130;
	private static final int CAPITAL_ZONE_H     = ZONE_MIDDLE_H;
	private static final int CAPITAL_ZONE_X     = BOARD_CENTER_X-CAPITAL_ZONE_W/2;
	private static final int CAPITAL_ZONE_Y     = HAND_ZONE_Y-CAPITAL_ZONE_H - 10;
	private static final int CAPITAL_ZONE_X_OPE = CAPITAL_ZONE_X;
	private static final int CAPITAL_ZONE_Y_OPE = HAND_ZONE_Y_OPE+HAND_ZONE_H+10;
	
	public static final int CAPITAL_BG_W  = 90;
	public static final int CAPITAL_BG_H  = 130;
	
	public static final float DECK_ZOOM   = 1.2f;
	
	private static final int DECK_ZONE_W     = (int) (CARD_W*DECK_ZOOM+15);
	private static final int DECK_ZONE_H     = (int) (CARD_H*DECK_ZOOM+15);
	private static final int DECK_ZONE_X     = 20;
	private static final int DECK_ZONE_Y     = BOARD_CENTER_Y + 20 ;
	private static final int DECK_ZONE_X_OPE = 20 ;
	private static final int DECK_ZONE_Y_OPE = BOARD_CENTER_Y - DECK_ZONE_H - 20 ;
	
	private static final int DISCARD_ZONE_W     = DECK_ZONE_W;
	private static final int DISCARD_ZONE_H     = DECK_ZONE_H;
	private static final int DISCARD_ZONE_X     = 20;
	private static final int DISCARD_ZONE_Y     = DECK_ZONE_Y + DECK_ZONE_H +10 ;
	private static final int DISCARD_ZONE_X_OPE = DECK_ZONE_X_OPE ;
	private static final int DISCARD_ZONE_Y_OPE = DECK_ZONE_Y_OPE - DISCARD_ZONE_H - 10 ;
	
	private static final int KINGDOM_ZONE_W     = CARD_W*4 + 25;
	private static final int KINGDOM_ZONE_H     = ZONE_MIDDLE_H;
	private static final int KINGDOM_ZONE_X     = CAPITAL_ZONE_X-KINGDOM_ZONE_W ;
	private static final int KINGDOM_ZONE_Y     = CAPITAL_ZONE_Y;
	private static final int KINGDOM_ZONE_X_OPE = CAPITAL_ZONE_X_OPE+CAPITAL_ZONE_W ;
	private static final int KINGDOM_ZONE_Y_OPE = CAPITAL_ZONE_Y_OPE;
	private static final int KINGDOM_CARD_Y1             = KINGDOM_ZONE_Y + 5 ;
	private static final int KINGDOM_CARD_CORRUPT_Y1     = KINGDOM_ZONE_Y + 20;
	private static final int KINGDOM_CARD_Y2             = KINGDOM_ZONE_Y + 10+ CARD_H;
	private static final int KINGDOM_CARD_CORRUPT_Y2     = KINGDOM_ZONE_Y + 20+ CARD_H;
	private static final int KINGDOM_CARD_Y1_OPE         = KINGDOM_ZONE_Y_OPE + 10 + CARD_H;
	private static final int KINGDOM_CARD_CORRUPT_Y1_OPE = KINGDOM_ZONE_Y_OPE + 20+ CARD_H;	
	private static final int KINGDOM_CARD_Y2_OPE         = KINGDOM_ZONE_Y_OPE + 5 ;
	private static final int KINGDOM_CARD_CORRUPT_Y2_OPE = KINGDOM_ZONE_Y_OPE + 20;	
	
	private static final int QUEST_ZONE_W     = KINGDOM_ZONE_W;
	private static final int QUEST_ZONE_H     = ZONE_MIDDLE_H;
	private static final int QUEST_ZONE_X     = CAPITAL_ZONE_X+CAPITAL_ZONE_W ;
	private static final int QUEST_ZONE_Y     = CAPITAL_ZONE_Y;
	private static final int QUEST_ZONE_X_OPE = CAPITAL_ZONE_X_OPE-QUEST_ZONE_W ;
	private static final int QUEST_ZONE_Y_OPE = CAPITAL_ZONE_Y_OPE ;
	private static final int QUEST_CARD_Y1             = KINGDOM_CARD_Y1;
	private static final int QUEST_CARD_CORRUPT_Y1     = KINGDOM_CARD_CORRUPT_Y1;
	private static final int QUEST_CARD_Y2             = KINGDOM_CARD_Y2;
	private static final int QUEST_CARD_CORRUPT_Y2     = KINGDOM_CARD_CORRUPT_Y2;
	private static final int QUEST_CARD_Y1_OPE         = KINGDOM_CARD_Y1_OPE;
	private static final int QUEST_CARD_CORRUPT_Y1_OPE = KINGDOM_CARD_CORRUPT_Y1_OPE;	
	private static final int QUEST_CARD_Y2_OPE         = KINGDOM_CARD_Y2_OPE;
	private static final int QUEST_CARD_CORRUPT_Y2_OPE = KINGDOM_CARD_CORRUPT_Y2_OPE;		
	
	private static final int BATTLE_ZONE_W         = BOARD_WIDTH-100-100-30;
	private static final int BATTLE_ZONE_H         = CARD_H +10 ;
	private static final int BATTLE_ZONE_X         = BOARD_CENTER_X-BATTLE_ZONE_W/2 ;
	private static final int BATTLE_ZONE_Y         = CAPITAL_ZONE_Y-BATTLE_ZONE_H -10;
	private static final int BATTLE_ZONE_X_OPE     = BATTLE_ZONE_X;
	private static final int BATTLE_ZONE_Y_OPE     = CAPITAL_ZONE_Y_OPE+CAPITAL_ZONE_H+10;
	private static final int BATTLE_CARD_Y         = BATTLE_ZONE_Y + 5 ;
	private static final int BATTLE_CARD_CORRUPT_Y = BATTLE_ZONE_Y + 20;
	private static final int BATTLE_CARD_Y_OPE     = BATTLE_ZONE_Y_OPE + 5 ;
	private static final int BATTLE_CARD_CORRUPT_Y_OPE = BATTLE_ZONE_Y_OPE + 20;
	private static final int BATTLE_LABEL_X        = BATTLE_ZONE_X+BATTLE_ZONE_W/2 -32;
	private static final int BATTLE_LABEL_Y        = BATTLE_ZONE_Y+BATTLE_ZONE_H/2 +9;
	private static final String BATTLE_LABEL_STR   = "战场区";

	private static final Color colorDiy1       = new Color(200,200,200);
	private static final Color colorPhasesLast = new Color(200,200,200);
	private static final Color colorPhasesOpe  = new Color(255,0,0);
	private static final Color colorPhasesMy   = new Color(0,0,255);
	
	private static final Font FONT_NORMAL       = new Font("宋体", Font.LAYOUT_NO_LIMIT_CONTEXT, 12);
	private static final Font FONT_PHASES_TITLE = new Font("黑体", Font.BOLD, 16);
	private static final Font FONT_PHASES       = new Font("宋体", Font.BOLD, 12);
	private static final Font FONT_BIG_CENTER   = new Font("黑体", Font.BOLD, 20);
	
	private boolean repaintAll = true;
	
	private BufferedImage cardUnfindImage = null;
	private BufferedImage cardBackImage = null;
	private BufferedImage capitalImage = null;
	private BufferedImage capitalImageOperate = null;
	private Map<String,BufferedImage> cardBufferedImageMap = new HashMap<String, BufferedImage>();
	private Map<Integer,CardLabel> cardMotionMap = new HashMap<Integer, CardLabel>();
	
	private GameBoardDouble gameBoard ;
	private MotionPlayerZone player ;
	public  MotionCard   previewCard;
	
	public MainFrame(GameBoardDouble gameBoard ,MotionPlayerZone player){
		this.gameBoard = gameBoard;
		this.player = player ;
		player.mainFrame = this;
		
		try {
			this.cardBackImage = ImageIO.read(new File(ConstantPicture.PIC_CARD_BACK));
			this.cardUnfindImage = ImageIO.read(new File(ConstantPicture.PIC_CARD_UNFIND));
			String capPicPath = ConstantCardRace.mapRaceCapitalFile.get(player.getCapitalRaceType());
			capitalImage = ImageIO.read(new File(capPicPath));
			String capPicPathOperate = ConstantCardRace.mapRaceCapitalFile.get(player.operatePlayer.getCapitalRaceType());
			capitalImageOperate = ImageIO.read(new File(capPicPathOperate));
		} catch (Exception e) {
			// TODO: handle exception
		}

		initDisplay();
		initEventAndListener();
		reload();
	}
	
	// =========================================================================
	// =====================   窗口初始化操作     ==================================
	// =========================================================================
	
	private PreviewCardLabel previewPanel = null;
	private JTextPane previewDescPane = new JTextPane();
//	private JPanel mainPanel = new JPanel();
	Border borderEmpty = BorderFactory.createEmptyBorder();
	Border border1 = new BevelBorder(BevelBorder.LOWERED);
	Border borderLineGray1 = new LineBorder(Color.lightGray, 1);
	Border borderLine = new LineBorder(Color.gray, 3);
	Border[] bordersZoneBeAttack = {
			new LineBorder(new Color(150,0,0), 2),
			new LineBorder(new Color(180,0,0), 2),
			new LineBorder(new Color(210,0,0), 2),
			new LineBorder(new Color(230,0,0), 2),
			new LineBorder(new Color(250,0,0), 2),
			new LineBorder(new Color(230,0,0), 2),
			new LineBorder(new Color(210,0,0), 2),
			new LineBorder(new Color(180,0,0), 2),
			new LineBorder(new Color(150,0,0), 2),
	};
	
	/** 闪亮:当前的样式 */
    private int switchStyleZoneBeAttackIndex = 0;
    
	private JPanel phasesPanel = new JPanel();
	
	JLabel phases_turn_text       = new JLabel();
	
	JPanel boardPanel = new JPanel();
	JPanel handZonePanel = new JPanel();
	JTextPane playerInfoPanel = new JTextPane();
	JTextPane playerOperateInfoPanel = new JTextPane();
	DeskCardLabel deskPanel ;
	DeskCardLabel deskOpePanel ;
	DisCardLabel discardPanel ;
	DisCardLabel discardOpePanel ;
	HandZoneLabel handBorder ;
	HandZoneLabel handOpeBorder ;
	JLabel battleBorder ;
	JLabel battleOpeBorder ;
	JLabel kingdomBorder ;
	JLabel kingdomOpeBorder ;
	JLabel questBorder ;
	JLabel questOpeBorder ;
	CapitalLabel capitalBorder ;
	CapitalLabel capitalOpeBorder ;
	
	JPanel userCommand = new JPanel();
	FirstTurnBtn  firstTurnBtn ;
	NextPhasesBtn nextPhasesBtn ;
	AttackToBattleZoneBtn attackToBattleBtn ;
	AttackToKingdomZoneBtn attackToKingdomBtn ;
	AttackToQuestZoneBtn attackToQuestBtn ;
	FinishChooseAttackUnitBtn   finishChooseAttackUnitBtn ;
	FinishChooseDefendUnitBtn   finishChooseDefendUnitBtn ;
	FinishChooseAttackDamageBtn finishChooseAttackDmgBtn ;
	FinishChooseDefendDamageBtn finishChooseDefendDmgBtn ;
	SkipBattlePhasesBtn skipBattlePhasesBtn ;
	
	private void initDisplay(){
		
		this.setSize(WIN_WIDTH, WIN_HEIGHT);
		this.setTitle(WIN_TITLE+" ( "+player.playerName+" VS "+player.operatePlayer.playerName+" )");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.setLayout(null);
		
		// 回合区 START
		
		
		phasesPanel.setFont(new Font("宋体",Font.PLAIN, 14));
		phasesPanel.setBounds(PHASES_ZONE_X, PHASES_ZONE_Y, PHASES_ZONE_W ,PHASES_ZONE_H);
		phases_turn_text.setFont( FONT_PHASES_TITLE);
		phasesPanel.setLayout(new GridLayout(13,1,0,0));
		phasesPanel.add(phases_turn_text);
		phasesPanel.add(new Phases0BeginingBtn(player));
		phasesPanel.add(new Phases1KingdomBtn(player));
		phasesPanel.add(new Phases2QuestBtn(player));
		phasesPanel.add(new Phases3CapitalBtn(player));
		phasesPanel.add(new Phases4BattleBtn(player));
		phasesPanel.add(new Phases4Battle1ChooseZoneBtn(player));
		phasesPanel.add(new Phases4Battle2ChooseAttackBtn(player));
		phasesPanel.add(new Phases4Battle3ChooseDefendBtn(player));
		phasesPanel.add(new Phases4Battle4AttackDmgBtn(player));
		phasesPanel.add(new Phases4Battle5DefendDmgBtn(player));
		phasesPanel.add(new Phases4Battle6CalcDmgBtn(player));
		phasesPanel.add(new Phases5EndTurnBtn(player));
		this.add(phasesPanel);
		//~ 回合区 END


		// 预览卡片 START
		previewPanel = new PreviewCardLabel(player, this);
//		JLabel previewPanel = new JLabel();
		previewPanel.setBorder(BorderFactory.createRaisedBevelBorder());
		previewPanel.setBounds(PREVIEW_CARD_X, PREVIEW_CARD_Y , PREVIEW_CARD_W, PREVIEW_CARD_H);
		this.add(previewPanel);
		//~ 预览卡片 END
		
		// 预览卡片 文字区
		previewDescPane.setFont(new Font("宋体",Font.PLAIN, 14));
		previewDescPane.setBackground(Color.LIGHT_GRAY);
		previewDescPane.setBounds(PREVIEW_CARD_X, PREVIEW_CARD_Y+PREVIEW_CARD_H, PREVIEW_DESC_W, PREVIEW_DESC_H);
		this.add(previewDescPane);
		
		// 玩家信息区
		playerInfoPanel.setBounds(USER_LABEL_X, USER_LABEL_Y, USER_LABEL_WIDTH, USER_LABEL_HEIGHT);
		this.add(playerInfoPanel);
		// 对手信息区
		playerOperateInfoPanel.setBounds(USER_LABEL_X_OPE, USER_LABEL_Y_OPE, USER_LABEL_WIDTH, USER_LABEL_HEIGHT);
		this.add(playerOperateInfoPanel);
		
		// 游戏板
		boardPanel.setLayout(null);
		boardPanel.setDoubleBuffered(true);
		boardPanel.setBorder(BorderFactory.createLineBorder(Color.lightGray,1));
		boardPanel.setBounds(BOARD_X, BOARD_Y, BOARD_WIDTH, BOARD_HEIGHT);
		this.add(boardPanel);
		boardPanel.repaint();

		// 弃牌堆
		discardPanel = new DisCardLabel(player, player.discardPile);
		discardPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
		discardPanel.setBounds(DISCARD_ZONE_X, DISCARD_ZONE_Y, DISCARD_ZONE_W, DISCARD_ZONE_H);
		boardPanel.add(discardPanel);
		discardOpePanel = new DisCardLabel(player, player.operatePlayer.discardPile);
		discardOpePanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
		discardOpePanel.setBounds(DISCARD_ZONE_X_OPE, DISCARD_ZONE_Y_OPE, DISCARD_ZONE_W, DISCARD_ZONE_H);
		boardPanel.add(discardOpePanel);
		discardOpePanel.repaint();
		
		//~弃牌堆~~~~
		// 抽牌堆
		deskPanel = new DeskCardLabel(player, player.deskZone);
		deskPanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
		deskPanel.setBounds(DECK_ZONE_X, DECK_ZONE_Y, DECK_ZONE_W, DECK_ZONE_H);
		boardPanel.add(deskPanel);
		deskPanel.repaint();
		deskOpePanel = new DeskCardLabel(player, player.operatePlayer.deskZone);
		deskOpePanel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
		deskOpePanel.setBounds(DECK_ZONE_X_OPE, DECK_ZONE_Y_OPE, DECK_ZONE_W, DECK_ZONE_H);
		boardPanel.add(deskOpePanel);
		deskOpePanel.repaint();
		//~抽牌堆
		
		// 各种区域 START ========================
		// 我的手牌
		handBorder = new HandZoneLabel(player, player.handZone);
		handBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		handBorder.setBounds(HAND_ZONE_X, HAND_ZONE_Y, HAND_ZONE_W, HAND_ZONE_H);
		boardPanel.add(handBorder);
		handBorder.repaint();
		// 对方手牌
		handOpeBorder = new HandZoneLabel(player, player.operatePlayer.handZone);
		handOpeBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		handOpeBorder.setBounds(HAND_ZONE_X_OPE, HAND_ZONE_Y_OPE, HAND_ZONE_W, HAND_ZONE_H);
		boardPanel.add(handOpeBorder);
		handOpeBorder.repaint();
		// 我的首都区域
		capitalBorder = new CapitalLabel(player, player.capitalZone , player.getCapitalRaceType());
		capitalBorder.setBounds(CAPITAL_ZONE_X, CAPITAL_ZONE_Y, CAPITAL_ZONE_W, CAPITAL_ZONE_H);
		boardPanel.add(capitalBorder);
		capitalBorder.repaint();
		// 对方首都区域
		capitalOpeBorder = new CapitalLabel(player, player.operatePlayer.capitalZone , player.operatePlayer.getCapitalRaceType());
		capitalOpeBorder.setBounds(CAPITAL_ZONE_X_OPE, CAPITAL_ZONE_Y_OPE, CAPITAL_ZONE_W, CAPITAL_ZONE_H);
		boardPanel.add(capitalOpeBorder);
		capitalOpeBorder.repaint();
		// 我的战场区域
		battleBorder = new JLabel();
		battleBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		battleBorder.setBounds(BATTLE_ZONE_X, BATTLE_ZONE_Y, BATTLE_ZONE_W, BATTLE_ZONE_H);
		boardPanel.add(battleBorder);
		// 对方战场区域
		battleOpeBorder = new JLabel();
		battleOpeBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		battleOpeBorder.setBounds(BATTLE_ZONE_X_OPE, BATTLE_ZONE_Y_OPE, BATTLE_ZONE_W, BATTLE_ZONE_H);
		boardPanel.add(battleOpeBorder);
		// 我的王国区域
		kingdomBorder = new JLabel();
		kingdomBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		kingdomBorder.setBounds(KINGDOM_ZONE_X, KINGDOM_ZONE_Y, KINGDOM_ZONE_W, KINGDOM_ZONE_H);
		boardPanel.add(kingdomBorder);
		// 对方王国区域
		kingdomOpeBorder = new JLabel();
		kingdomOpeBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		kingdomOpeBorder.setBounds(KINGDOM_ZONE_X_OPE, KINGDOM_ZONE_Y_OPE, KINGDOM_ZONE_W, KINGDOM_ZONE_H);
		boardPanel.add(kingdomOpeBorder);
		// 我的任务区域
		questBorder = new JLabel();
		questBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		questBorder.setBounds(QUEST_ZONE_X, QUEST_ZONE_Y, QUEST_ZONE_W, QUEST_ZONE_H);
		boardPanel.add(questBorder);
		// 对方任务区域
		questOpeBorder = new JLabel();
		questOpeBorder.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY,1));
		questOpeBorder.setBounds(QUEST_ZONE_X_OPE, QUEST_ZONE_Y_OPE, QUEST_ZONE_W, QUEST_ZONE_H);
		boardPanel.add(questOpeBorder);
		//~各种区域 END ~~~~~~~~~~~~~~~~~~~~~~~~~~~
		
		// 用户指令区
		GridLayout layout = new GridLayout(5,1);
		layout.setHgap(5);
		layout.setVgap(5);
		userCommand.setLayout(layout);
		userCommand.setBounds(USER_COMMAND_X, USER_COMMAND_Y, USER_COMMAND_W, USER_COMMAND_H);
		firstTurnBtn  = new FirstTurnBtn(this.player);
		attackToBattleBtn  = new AttackToBattleZoneBtn(this.player);
		attackToKingdomBtn  = new AttackToKingdomZoneBtn(this.player);
		attackToQuestBtn  = new AttackToQuestZoneBtn(this.player);
		skipBattlePhasesBtn  = new SkipBattlePhasesBtn(this.player);
		finishChooseAttackUnitBtn  = new FinishChooseAttackUnitBtn(this.player);
		finishChooseDefendUnitBtn  = new FinishChooseDefendUnitBtn(this.player);
		finishChooseAttackDmgBtn  = new FinishChooseAttackDamageBtn(this.player);
		finishChooseDefendDmgBtn  = new FinishChooseDefendDamageBtn(this.player);
		nextPhasesBtn = new NextPhasesBtn(this.player);
		boardPanel.add(userCommand);
		//~用户指令区
		
		this.setVisible(true);
	}
	
	
	private void initEventAndListener(){
		this.addMouseListener(this);
	}
	
	public void reload(){
		reloadLabel();
		reloadPreview();
		reloadPhases();
		reloadZoneDesk();
		reloadZoneDiscard();
		reloadZoneHand();
		reloadZoneKingdom();
		reloadZoneQuest();
		reloadZoneBattle();
		reloadUserCommand();
	}
	
	
	/**
	 * 重绘:回合
	 */
	public void reloadPhases(){

		phasesPanel.repaint();
		
		if(player.isMyTurn){
			phases_turn_text.setText("我的回合");
		}else if(player.operatePlayer.isMyTurn){
			phases_turn_text.setText("对方回合");
		}else{
			return ;
		}
	}

	
	/**
	 * 重绘:抽牌区
	 */ 
	public void reloadZoneDesk(){
		deskPanel.repaint();
		deskOpePanel.repaint();
	}
	
	/**
	 * 重绘:弃牌区
	 */ 
	public void reloadZoneDiscard(){
		discardPanel.repaint();
		discardOpePanel.repaint();
	}
	
	
	/**
	 * 重绘:手牌
	 * @param g2D
	 */
	public void reloadZoneHand(){
		handBorder.repaint();
		handOpeBorder.repaint();
		int padding = 3;
		int maxSize = (HAND_ZONE_W - padding*2) / CARD_W ;
		int stepX = CARD_W +padding ;
		
		if(repaintAll || this.player.handZone.isNeedRepaint()){			
			if(this.player.handZone.getCardSize()>maxSize){ 
				//注：即使考虑极端情况，maxSize最小为0，cardSize>maxSize,所以最小为1，所以这里除数不会出现为0
				stepX = (HAND_ZONE_W - padding*2 )/ this.player.handZone.getCardSize();
			}
			for(int i=0; i<this.player.handZone.getCardSize(); i++){
				MotionCard motionCard = player.handZone.getCards().get(i);
				CardLabel cardLabel = null;
				if(cardMotionMap.get(motionCard.uniqueKey)==null){
					cardLabel = new CardLabel(player, motionCard);
					cardLabel.setBounds(HAND_ZONE_X+i*stepX+padding, HAND_ZONE_Y+padding , CARD_W, CARD_H);
					cardLabel.addMouseListener(cardLabel);
					boardPanel.add(cardLabel);
					cardLabel.repaint();
					cardMotionMap.put(motionCard.uniqueKey, cardLabel);
				}else{
					cardLabel = cardMotionMap.get(motionCard.uniqueKey);
					cardLabel.setBounds(HAND_ZONE_X+i*stepX+padding, HAND_ZONE_Y+padding , CARD_W, CARD_H);
				}
			}
		}
		
		if(repaintAll || this.player.operatePlayer.handZone.isNeedRepaint()){
			if(this.player.operatePlayer.handZone.getCardSize()>maxSize){ 
				stepX = (HAND_ZONE_W - padding*2 )/ this.player.operatePlayer.handZone.getCardSize();
			}
			for(int i=0; i<this.player.operatePlayer.handZone.getCardSize(); i++){
				MotionCard motionCard = player.operatePlayer.handZone.getCards().get(i);
				CardLabel cardLabel = null;
				if(cardMotionMap.get(motionCard.uniqueKey)==null){
					cardLabel = new CardLabel(player, motionCard);
					cardLabel.setBounds(HAND_ZONE_X+i*stepX+padding, HAND_ZONE_Y_OPE+padding , CARD_W, CARD_H);
					cardLabel.addMouseListener(cardLabel);
					boardPanel.add(cardLabel);
					cardLabel.repaint();
					cardMotionMap.put(motionCard.uniqueKey, cardLabel);
				}else{
					cardLabel = cardMotionMap.get(motionCard.uniqueKey);
					cardLabel.setBounds(HAND_ZONE_X+i*stepX+padding, HAND_ZONE_Y_OPE+padding , CARD_W, CARD_H);
				}
			}
		}
		
	}
	

	
	/**
	 * 重绘:王国区
	 * 注：只需考虑放置的X,Y,W,H，不用考虑正面或背面
	 * @throws Exception 
	 */
	public void reloadZoneKingdom() {

		if(player.kingdomZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.kingdomBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.kingdomBorder.setBorder(borderLineGray1);
		}
		
		if(player.operatePlayer.kingdomZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.kingdomOpeBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.kingdomOpeBorder.setBorder(borderLineGray1);
		}
		
		int padding = 3;
		int nextX = KINGDOM_ZONE_X + padding;
		
		// 我方王国区第一排 =====================================================
		// 假设每一张卡都是横放的,并且互不重叠最多可以放置几张？
		int maxSize = (KINGDOM_ZONE_W-10)/(CARD_H+padding);  
		int stepX = CARD_H+2;
		if(player.kingdomZone.getCardSizeRow1()>maxSize){
			stepX = (KINGDOM_ZONE_W-10)/player.kingdomZone.getCardSizeRow1();
		}
		for(MotionCard card : player.kingdomZone.getCardsRow1()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 注：这里不该出现设施卡
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_SUPPORT){
				// 注：这里不应该出现支援卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				if(card.getQuestUnitCard()==null){
					// TODO : 绘制任务卡
				}else{
					// 注：这里不应该出现有部队的任务卡
				}
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , KINGDOM_CARD_CORRUPT_Y1 , CARD_H, CARD_W);
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , KINGDOM_CARD_Y1 , CARD_W, CARD_H);
					nextX += stepX ;
				}
			}
		}
		
		// 我方王国区第二排 =====================================================
		nextX = KINGDOM_ZONE_X + padding;
		maxSize = (KINGDOM_ZONE_W-10)/(CARD_W+padding); // 第二排不考虑横置
		stepX = CARD_W+2;
		if(player.kingdomZone.getCardSizeRow2()>maxSize){
			stepX = (KINGDOM_ZONE_W-10)/player.kingdomZone.getCardSizeRow2();
		}
		for(MotionCard card : player.kingdomZone.getCardsRow2()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				cardLabel.setBounds(nextX , KINGDOM_CARD_Y2 , CARD_W, CARD_H);
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				// 注：这里不应该出现任务卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_UNIT){
				// 注：这里不应该出现单位卡
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , KINGDOM_CARD_CORRUPT_Y2 , CARD_H, CARD_W);
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , KINGDOM_CARD_Y2 , CARD_W, CARD_H);
					nextX += stepX ;
				}
			}
		}
		
		
		// 对方王国区第一排 =====================================================
		// 假设每一张卡都是横放的,并且互不重叠最多可以放置几张？
		nextX = KINGDOM_ZONE_X_OPE + padding;
		maxSize = (KINGDOM_ZONE_W-10)/(CARD_H+padding);  
		stepX = CARD_H+2;
		if(player.operatePlayer.kingdomZone.getCardSizeRow1()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.operatePlayer.kingdomZone.getCardSizeRow1();
		}
		for(MotionCard card : player.operatePlayer.kingdomZone.getCardsRow1()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 注：这里不该出现设施卡
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_SUPPORT){
				// 注：这里不应该出现支援卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				if(card.getQuestUnitCard()==null){
					// TODO : 绘制任务卡
				}else{
					// 注：这里不应该出现有部队的任务卡
				}
			}else {
				// TODO : 显示它的附加卡、任务卡
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , KINGDOM_CARD_CORRUPT_Y1_OPE , CARD_H, CARD_W);
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , KINGDOM_CARD_Y1_OPE , CARD_W, CARD_H);
					nextX += stepX ;
				}
			}
		}
		
		// 对方王国区第二排 =====================================================
		nextX = KINGDOM_ZONE_X_OPE + padding;
		maxSize = (KINGDOM_ZONE_W-10)/(CARD_W+padding); // 第二排不考虑横置
		stepX = CARD_W+2;
		if(player.operatePlayer.kingdomZone.getCardSizeRow2()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.operatePlayer.kingdomZone.getCardSizeRow2();
		}
		for(MotionCard card : player.operatePlayer.kingdomZone.getCardsRow2()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				cardLabel.setBounds(nextX , KINGDOM_CARD_Y2_OPE , CARD_W, CARD_H);
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				// 注：这里不应该出现任务卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_UNIT){
				// 注：这里不应该出现单位卡
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , KINGDOM_CARD_CORRUPT_Y2_OPE , CARD_H, CARD_W);
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , KINGDOM_CARD_Y2_OPE , CARD_W, CARD_H);
					nextX += stepX ;
				}
			}
		}
	}
	
	/**
	 * 重绘:任务区
	 * 注：只需考虑放置的X,Y,W,H，不用考虑正面或背面
	 * @throws Exception 
	 */
	public void reloadZoneQuest() {
		
		if(player.questZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.questBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.questBorder.setBorder(borderLineGray1);
		}
		
		if(player.operatePlayer.questZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.questOpeBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.questOpeBorder.setBorder(borderLineGray1);
		}
		
		int padding = 3;
		int nextX = QUEST_ZONE_X + padding;
		
		// 我方任务区第一排 =====================================================
		// 假设每一张卡都是横放的,并且互不重叠最多可以放置几张？
		int maxSize = (QUEST_ZONE_W-10)/(CARD_H+padding);  
		int stepX = CARD_H+2;
		if(player.questZone.getCardSizeRow1()>maxSize){
			stepX = (QUEST_ZONE_W-10)/player.questZone.getCardSizeRow1();
		}
		for(MotionCard card : player.questZone.getCardsRow1()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 注：这里不该出现设施卡
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_SUPPORT){
				// 注：这里不应该出现支援卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				if(card.getQuestUnitCard()==null){
					// TODO : 绘制任务卡
				}else{
					// 注：这里不应该出现有部队的任务卡
				}
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , QUEST_CARD_CORRUPT_Y1 , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , QUEST_CARD_Y1 , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
		
		// 我方任务区第二排 =====================================================
		nextX = QUEST_ZONE_X + padding;
		maxSize = (QUEST_ZONE_W-10)/(CARD_W+padding); // 第二排不考虑横置
		stepX = CARD_W+2;
		if(player.questZone.getCardSizeRow2()>maxSize){
			stepX = (QUEST_ZONE_W-10)/player.questZone.getCardSizeRow2();
		}
		for(MotionCard card : player.questZone.getCardsRow2()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				cardLabel.setBounds(nextX , QUEST_CARD_Y2 , CARD_W, CARD_H);
				cardLabel.repaint();
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				// 注：这里不应该出现任务卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_UNIT){
				// 注：这里不应该出现单位卡
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , QUEST_CARD_CORRUPT_Y2 , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , QUEST_CARD_Y2 , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
		
		
		// 对方任务区第一排 =====================================================
		// 假设每一张卡都是横放的,并且互不重叠最多可以放置几张？
		nextX = QUEST_ZONE_X_OPE + padding;
		maxSize = (QUEST_ZONE_W-10)/(CARD_H+padding);  
		stepX = CARD_H+2;
		if(player.operatePlayer.questZone.getCardSizeRow1()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.operatePlayer.questZone.getCardSizeRow1();
		}
		for(MotionCard card : player.operatePlayer.questZone.getCardsRow1()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 注：这里不该出现设施卡
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_SUPPORT){
				// 注：这里不应该出现支援卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				if(card.getQuestUnitCard()==null){
					// TODO : 绘制任务卡
				}else{
					// 注：这里不应该出现有部队的任务卡
				}
			}else {
				// TODO : 显示它的附加卡、任务卡
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , QUEST_CARD_CORRUPT_Y1_OPE , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , QUEST_CARD_Y1_OPE , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
		
		// 对方任务区第二排 =====================================================
		nextX = QUEST_ZONE_X_OPE + padding;
		maxSize = (QUEST_ZONE_W-10)/(CARD_W+padding); // 第二排不考虑横置
		stepX = CARD_W+2;
		if(player.operatePlayer.questZone.getCardSizeRow2()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.operatePlayer.questZone.getCardSizeRow2();
		}
		for(MotionCard card : player.operatePlayer.questZone.getCardsRow2()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				cardLabel.setBounds(nextX , QUEST_CARD_Y2_OPE , CARD_W, CARD_H);
				cardLabel.repaint();
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 注：这里不应该出现附加卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_QUEST){
				// 注：这里不应该出现任务卡
			}else if(card.cardEntity.getType()==ConstantCardType.CARD_TYPE_UNIT){
				// 注：这里不应该出现单位卡
			}else {
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , QUEST_CARD_CORRUPT_Y2_OPE , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , QUEST_CARD_Y2_OPE , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
	}

    
	/**
	 * 重绘:战场区
	 * 注：只需考虑放置的X,Y,W,H，不用考虑正面或背面
	 */
	public void reloadZoneBattle(){
		
		if(player.battleZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.battleBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.battleBorder.setBorder(borderLineGray1);
		}
		
		if(player.operatePlayer.battleZone.isBeAttacked()){
			if(switchStyleZoneBeAttackIndex<0 ||
					switchStyleZoneBeAttackIndex>=bordersZoneBeAttack.length){
				switchStyleZoneBeAttackIndex = 0;
			}
			this.battleOpeBorder.setBorder(bordersZoneBeAttack[switchStyleZoneBeAttackIndex]);
			switchStyleZoneBeAttackIndex++;
		}else{
			this.battleOpeBorder.setBorder(borderLineGray1);
		}
		
		player.battleZone.sortCard();
		int padding = 3;
		int normalY = BATTLE_CARD_Y; // 普通卡的Y座标
		int corruptY = BATTLE_CARD_CORRUPT_Y; // 折叠后的Y座标
		int nextX = BATTLE_ZONE_X + padding;
		// 假设每一张卡都是横放的,并且互不重叠最多可以放置几张？(不含附加卡)
		int maxSize = (BATTLE_ZONE_W-10)/(CARD_H+padding);  
		int stepX = CARD_H+2;
		if(player.battleZone.getCardSizeOneRow()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.battleZone.getCardSizeOneRow();
		}
		for(MotionCard card : player.battleZone.getCardsOneRow()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 设施卡背面朝上,不考虑翻转
				cardLabel.setBounds(nextX , normalY , CARD_W, CARD_H);
				cardLabel.repaint();
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 附加卡在这里不直接显示
				// do nothing
			}else {
				// TODO : 显示它的附加卡
				BufferedImage image = cardBufferedImageMap.get( card.cardEntity.getUniqueStr() );
				if(image == null){
					try {
						image = card.cardEntity.getBufferedImage();
						cardBufferedImageMap.put( card.cardEntity.getUniqueStr(), image);
					} catch (IOException e) {
						image = cardUnfindImage;
						e.printStackTrace();
					}
				}
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , corruptY , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , normalY , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
		
		player.operatePlayer.battleZone.sortCard();
		normalY = BATTLE_CARD_Y_OPE; // 普通卡的Y座标
		corruptY = BATTLE_CARD_CORRUPT_Y_OPE; // 折叠后的Y座标
		nextX = BATTLE_ZONE_X_OPE + padding;
		stepX = CARD_H+2;
		if(player.operatePlayer.battleZone.getCardSizeOneRow()>maxSize){
			stepX = (BATTLE_ZONE_W-10)/player.operatePlayer.battleZone.getCardSizeOneRow();
		}
		for(MotionCard card : player.operatePlayer.battleZone.getCardsOneRow()){
			CardLabel cardLabel = null;
			if(cardMotionMap.get(card.uniqueKey)==null){
				cardLabel = new PlayZoneCardLabel(player.operatePlayer, card);
				cardLabel.addMouseListener(cardLabel);
				boardPanel.add(cardLabel);
				cardLabel.repaint();
				cardMotionMap.put(card.uniqueKey, cardLabel);
			}else{
				cardLabel = cardMotionMap.get(card.uniqueKey);
			}
			
			if(card.isDevelopment()){
				// 设施卡背面朝上,不考虑翻转
				cardLabel.setBounds(nextX , normalY , CARD_W, CARD_H);
				cardLabel.repaint();
				nextX += stepX ;
			}else if(card.isAttachment()){
				// 附加卡在这里不直接显示
				// do nothing
			}else {
				// TODO : 显示它的附加卡
				BufferedImage image = cardBufferedImageMap.get( card.cardEntity.getUniqueStr() );
				if(image == null){
					try {
						image = card.cardEntity.getBufferedImage();
						cardBufferedImageMap.put( card.cardEntity.getUniqueStr(), image);
					} catch (IOException e) {
						image = cardUnfindImage;
						e.printStackTrace();
					}
				}
				if(card.isCorrupt()){
					cardLabel.setBounds(nextX , corruptY , CARD_H, CARD_W);
					cardLabel.repaint();
					nextX += stepX ;
				}else{
					cardLabel.setBounds(nextX , normalY , CARD_W, CARD_H);
					cardLabel.repaint();
					nextX += stepX ;
				}
			}
		}
	}
	

	/**
	 * 重绘:玩家当前可做操作
	 */
	public void reloadUserCommand(){
		userCommand.removeAll();
		userCommand.repaint();
		firstTurnBtn.checkAndAddIn(userCommand);
		attackToBattleBtn.checkAndAddIn(userCommand);
		attackToKingdomBtn.checkAndAddIn(userCommand);
		attackToQuestBtn.checkAndAddIn(userCommand);
		skipBattlePhasesBtn.checkAndAddIn(userCommand);
		finishChooseAttackUnitBtn.checkAndAddIn(userCommand);
		finishChooseDefendUnitBtn.checkAndAddIn(userCommand);
		finishChooseAttackDmgBtn.checkAndAddIn(userCommand);
		finishChooseDefendDmgBtn.checkAndAddIn(userCommand);
		nextPhasesBtn.checkAndAddIn(userCommand);
	}
	
	/**
	 * 清除:清除用户所有操作
	 */
	public void clearUserCommand(){
		userCommand.removeAll();
	}
	
	
	/**
	 * 重绘:玩家信息
	 */
	public void reloadLabel(){
		StringBuffer myInfo = new StringBuffer();
		StringBuffer opeInfo = new StringBuffer();
		
		myInfo.append("玩家:"+player.playerName);
		myInfo.append("\n战场区: "+this.player.battleZone.getLabelHealthAndDefend());
		myInfo.append("\n王国区: "+this.player.kingdomZone.getLabelHealthAndDefend());
		myInfo.append("\n任务区: "+this.player.questZone.getLabelHealthAndDefend() );
		if(ConstantCardTeamLimit.allRaceWithTeam.get(player.getCapitalRaceType())==ConstantCardTeamLimit.CARD_TEAM_ORDER){
			myInfo.append("\n<矮人/帝国/高精>" );
			myInfo.append("\n "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_DWARF) );
			myInfo.append(" / "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_EMPIRE) );
			myInfo.append(" / "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_HIGHELF));
		}else if(ConstantCardTeamLimit.allRaceWithTeam.get(player.getCapitalRaceType())==ConstantCardTeamLimit.CARD_TEAM_Destruction){
			myInfo.append("\n<兽人/混沌/暗精>" );
			myInfo.append("\n "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_ORC) );
			myInfo.append(" / "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_CHAOS) );
			myInfo.append(" / "+player.getTeamRaceFlag(ConstantCardRace.CARD_RACE_DARKELF) );
		}
		myInfo.append("\n资源: "+this.player.getResource() );
		
		opeInfo.append("玩家:"+player.operatePlayer.playerName );
		opeInfo.append("\n战场区: "+this.player.operatePlayer.battleZone.getLabelHealthAndDefend()  );
		opeInfo.append("\n王国区: "+this.player.operatePlayer.kingdomZone.getLabelHealthAndDefend()  );
		opeInfo.append("\n任务区: "+this.player.operatePlayer.questZone.getLabelHealthAndDefend()  );
		if(ConstantCardTeamLimit.allRaceWithTeam.get(player.operatePlayer.getCapitalRaceType())==ConstantCardTeamLimit.CARD_TEAM_ORDER){
			opeInfo.append("\n<矮人/帝国/高精>"  );
			opeInfo.append("\n "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_DWARF) );
			opeInfo.append(" / "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_EMPIRE) );
			opeInfo.append(" / "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_HIGHELF));			
		}else if(ConstantCardTeamLimit.allRaceWithTeam.get(player.operatePlayer.getCapitalRaceType())==ConstantCardTeamLimit.CARD_TEAM_Destruction){
			opeInfo.append("\n<兽人/混沌/暗精>" );
			opeInfo.append("\n "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_ORC) );
			opeInfo.append(" / "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_CHAOS) );
			opeInfo.append(" / "+player.operatePlayer.getTeamRaceFlag(ConstantCardRace.CARD_RACE_DARKELF) );
		}
		opeInfo.append("\n资源: "+this.player.operatePlayer.getResource() );
		playerInfoPanel.setText(myInfo.toString());
		playerOperateInfoPanel.setText(opeInfo.toString());
	}
	
	/**
	 * 重绘:预览卡片
	 */
	public void reloadPreview(){
		if(this.previewCard!=null){
			previewPanel.repaint();
			if(this.previewCard.checkVisiblePlayer(player)){
				StringBuffer description = new StringBuffer();
				description.append("【名称】\t").append(previewCard.cardEntity.getName());
				description.append("\n【类型】\t").append(ConstantCardType.allCardType.get(previewCard.cardEntity.getType()));
				description.append("\n【种族】\t").append(ConstantCardRace.mapRaceDesc.get(previewCard.cardEntity.getRace()));
				description.append("\n【花费】\t").append(previewCard.cardEntity.getCost());
				description.append("\n【忠诚】\t").append(previewCard.cardEntity.getLoyal());
				description.append("\n【生命值】\t").append(previewCard.getHealthMax());
				description.append(" - ").append( previewCard.getDamageCount());
				description.append("\n【能力值】\t").append(previewCard.cardEntity.getPower());
				description.append("\n【描述】\n").append(previewCard.cardEntity.getRules());
				description.append("\n");
				description.append("\n＝＝＝调试信息＝＝＝");
				description.append("\n当前区域\t").append(ConstantPlayZone.allZone.get(previewCard.currentZone) );
				description.append("\n设施卡？\t").append(previewCard.isDevelopment());
				description.append("\n需背置？\t").append(previewCard.isFlip());
				description.append("\n被腐化？\t").append(previewCard.isCorrupt());
				description.append("\n");
				description.append("\n是附加卡？\t").append(previewCard.isAttachment());
				description.append("\n附加对象\t").append(previewCard.getAttachmentTo());
				description.append("\n");
				description.append("\n有附加卡？\t").append(previewCard.isHasAttachment());
				description.append("\n附加卡\t").append(previewCard.getAttachmentList());
				previewDescPane.setText(description.toString());
			}else{
				previewDescPane.setText(null);				
			}
		}
	}
	
	
	
	public void mouseClicked(MouseEvent e) {
//		int mods=e.getModifiers();
//		AreaDefind areaDefind = areaClickEvent.checkAreaZoneByDefind( e.getX(), e.getY() );
//		System.out.print("\t("+e.getX()+","+e.getY()+")");
//		if(areaDefind!=null && areaDefind.getMotionCard()!=null){
//			System.out.print("\t"+areaDefind.getMotionCard().cardEntity.getName() );
//			if( !areaDefind.getMotionCard().equals( this.previewCard ) ){
//				this.previewCard = areaDefind.getMotionCard();
//				repaint(PREVIEW_AREA_X, PREVIEW_AREA_Y , PREVIEW_AREA_W,PREVIEW_AREA_H);
//			}
//			if((mods & InputEvent.BUTTON3_MASK)!=0){
//				JPopupMenu jpopup = areaDefind.getMotionCard().cardEntity.genePopupMenu();
//				if(jpopup!=null){
//					jpopup.show(e.getComponent(), e.getX(), e.getY());  
//				}
//			}
//		}
//		System.out.println();
	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
	}

	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
	}


	
	
	// Get & Set 
	public void setPreviewCard(MotionCard previewCard) {
		this.previewCard = previewCard;
	}

	
}
